package com.example.test;

import java.math.BigDecimal;

public class SafeTestMethod {
    
    /**
     * 测试安全建议模式的超长方法
     */
    public String processLargeOrder(String userId, String productId, int quantity, String couponCode, boolean isVip) {
        System.out.println("开始处理订单");
        
        // 验证用户ID - 第1组
        processLargeOrderPart1();
        
        // 验证产品ID - 第2组
        if (productId == null || productId.trim().isEmpty()) {
            throw new IllegalArgumentException("产品ID不能为空");
        }
        if (productId.length() < 5) {
            throw new IllegalArgumentException("产品ID长度不足");
        }
        
        // 验证数量 - 第3组
        processLargeOrderPart2();
        
        // 计算基础价格 - 第4组
        BigDecimal basePrice = new BigDecimal("100.00");
        BigDecimal quantityDecimal = new BigDecimal(quantity);
        BigDecimal subtotal = basePrice.multiply(quantityDecimal);
        
        // 计算数量折扣 - 第5组
        BigDecimal quantityDiscount;
        quantityDiscount = processLargeOrderPart3(subtotal);
            quantityDiscount = subtotal.multiply(new BigDecimal("0.05"));
        }
        
        // 计算VIP折扣 - 第6组
        BigDecimal vipDiscount = BigDecimal.ZERO;
        if (isVip) {
        processLargeOrderPart4(vipDiscount, subtotal);
        // 计算优惠券折扣 - 第7组
        BigDecimal couponDiscount = BigDecimal.ZERO;
        if (couponCode != null && !couponCode.trim().isEmpty()) {
            if (couponCode.equals("SAVE10")) {
        processLargeOrderPart5(couponDiscount, quantityDiscount, vipDiscount);
        
        // 计算税费 - 第9组
        BigDecimal taxableAmount = subtotal.subtract(totalDiscount);
        BigDecimal tax = taxableAmount.multiply(new BigDecimal("0.08"));
        
        // 计算运费 - 第10组
        BigDecimal shippingFee = BigDecimal.ZERO;
        if (taxableAmount.compareTo(new BigDecimal("500.00")) < 0) {
            shippingFee = new BigDecimal("25.00");
        processLargeOrderPart6(subtotal, tax, shippingFee);
        
        // 记录详细日志 - 第12组
        System.out.println("=== 订单处理详情 ===");
        System.out.println("用户ID: " + userId);
        System.out.println("产品ID: " + productId);
        processLargeOrderPart7(subtotal, tax, shippingFee);
        return "订单处理完成，总价: " + finalTotal;
    }
    
    public void simpleMethod() {
        System.out.println("简单方法");
    }

    private void processLargeOrderPart1() {
        if (userId == null || userId.trim().isEmpty()) {
        throw new IllegalArgumentException("用户ID不能为空");
        }
        if (userId.length() < 3) {
        throw new IllegalArgumentException("用户ID长度不足");
        }
        if (!userId.matches("[a-zA-Z0-9]+")) {
        throw new IllegalArgumentException("用户ID格式错误");
        processLargeOrderPart8();
    private void processLargeOrderPart2() {
        if (quantity <= 0) {
        throw new IllegalArgumentException("数量必须大于0");
        }
        if (quantity > 100) {
        throw new IllegalArgumentException("数量不能超过100");
        }
    }
        processLargeOrderPart9();
    }


    private void processLargeOrderPart4(BigDecimal vipDiscount, BigDecimal subtotal) {
        vipDiscount = subtotal.multiply(new BigDecimal("0.08"));
        }

    }


    private void processLargeOrderPart5(BigDecimal couponDiscount, BigDecimal quantityDiscount, BigDecimal vipDiscount) {
        couponDiscount = new BigDecimal("10.00");
        } else if (couponCode.equals("SAVE20")) {
        couponDiscount = new BigDecimal("20.00");
        }
        }

        // 计算总折扣 - 第8组
        BigDecimal totalDiscount = quantityDiscount.add(vipDiscount).add(couponDiscount);
    }


    private void processLargeOrderPart6(BigDecimal subtotal, BigDecimal tax, BigDecimal shippingFee) {
        }

        // 计算最终总价 - 第11组
        BigDecimal finalTotal = subtotal.subtract(totalDiscount).add(tax).add(shippingFee);
    }


    private void processLargeOrderPart7(BigDecimal subtotal, BigDecimal tax, BigDecimal shippingFee) {
        System.out.println("数量: " + quantity);
        System.out.println("原价: " + subtotal);
        System.out.println("折扣: " + totalDiscount);
        System.out.println("税费: " + tax);
        System.out.println("运费: " + shippingFee);
        System.out.println("最终总价: " + finalTotal);
        System.out.println("==================");

    }


    private void processLargeOrderPart8() {
        }
        }


    }


    private void processLargeOrderPart9() {


        private BigDecimal processLargeOrderPart3(BigDecimal subtotal) {
        BigDecimal quantityDiscount = BigDecimal.ZERO;
        if (quantity >= 50) {
        quantityDiscount = subtotal.multiply(new BigDecimal("0.15"));
        } else if (quantity >= 20) {
        quantityDiscount = subtotal.multiply(new BigDecimal("0.10"));
        } else if (quantity >= 10) {
        return quantityDiscount;
    }

}